


clear all
set more off

*global wd "C:\Users\kshih\Dropbox\Work\Research Projects\Active\chinese_students_2017"
global wd  "C:\Users\creto\Desktop\chinese_students_2017"
 
*global wd = "/Users/ariel/Dropbox/chinese_students_2017"


set scheme rbn2mono


*use "$wd\Data\1.ChinaData\UHS\UHS0209_house", clear
*use "$wd\Data\1.ChinaData\UHS\UHS0209_cleaned_combined", clear
use "$wd/Data/1.ChinaData/UHS/UHS0209_cleaned_combined", clear

//Drop those missing income info
drop if inc==.
gen nhouseholds=1
gen rentincome = (hrent_value) if hrent_num>0
gen rentshouse = hrent_num>0

gen anyrent = hrent_value>0 	
gen sh_rent = hrent_value/ inc

gen inc_0house = .
replace inc_0house = inc*(hnum==0)

gen inc_1house = .
replace inc_1house = inc*(hnum==1)

gen inc_2house = . 
replace inc_2house = inc*(hnum==2)

gen inc_3house = .
replace inc_3house = inc*(hnum>=3)

gen inc_multhouse = .
replace inc_multhouse = inc*(hnum>=2)

gen own_0house = (hnum==0)
gen own_1house = (hnum==1)
gen own_2house = (hnum==2)
gen own_3house = (hnum>=3)
gen own_multhouse = (hnum>=2)

gen hvalue_0house = hvalue*(hnum==0)
gen hvalue_1house = hvalue*(hnum==1)
gen hvalue_2house = hvalue*(hnum==2)
gen hvalue_3house = hvalue*(hnum>=3)
gen hvalue_multhouse = hvalue*(hnum>=2)
**FIGURES


	collapse (sum) nhouseholds rentshouse rentincome anyrent own_* inc_* hvalue_* (mean) credit hnum inc sh_rent hvalue [pw=wit], by(year)
	
	foreach x in 0 1 2 3 mult {
	gen avg_inc_`x'house = inc_`x'house / own_`x'house
	gen avg_hvalue_`x'house = hvalue_`x'house / own_`x'house
	gen sh_own_`x'house = own_`x'house / nhouseholds
	}

	foreach x in lab bus cap trans {
	gen avg_inc_`x' = inc_`x'/nhouseholds
	}
	gen sh_ownhouse = (own_1house + own_2house + own_3house)/nhouseholds
	gen sh_rentshouse = anyrent/nhouseholds
	gen sh_rentincome = rentincome/nhouseholds
	
	gen avg_inc_rent = rentincome/rentshouse
	
	
	
cd "$wd/Figures"

	**FIGURE A: HOUSING PRICES: AVG PRICE AND SHARE THAT OWN HH
	gr tw (connected hvalue year, color(red) lpattern(dash) ytitle("House Price (RMB)") ylabel(#5, format(%12.0fc))) ///
		  (connected avg_hvalue_multhouse year, color(red) lpattern(dash) msymb(Dh)) ///		
		  (connected sh_ownhouse year, color(blue) lpatter(solid) yaxis(2) ytitle("Share of Households", axis(2))) ///
		  if year<=2007, legend(label(1 "Avg. House Price") label(2 "Avg. House Price (Own >1 House)") label(3 "Share of HHs that Own House(s)") cols(1)) xtitle("") xlabel(,angle(0))
		  
		  graph export figd8_hprice.png, replace
		  
	
	*FIGURE C: INCOME BY HOMEOWNERSHIP 
	
	gr tw (connected avg_inc_0house year, color(black) lpattern(dash) msymb(Dh) ylabel(#5, format(%12.0fc)) ytitle("Avg. HH Income (RMB)")) ///
		  (connected avg_inc_1house year, color(black) lpattern(dash) msymb(diamond)) ///
		  (connected avg_inc_multhouse year, color(black) lpattern(solid) msymb(circ)) ///
		  if year<=2007, legend(label(1 "Non-Homeowner") label(2 "Owns 1 House") label(3 "Owns >1 Houses") cols(1)) xtitle("") xlabel(,angle(0))
		  graph export figd8_incbyhouse.png, replace

		  
	**FIGURE D:	OTHER SOURCES OF INCOME
	gr tw (connected avg_inc_lab year, color(black) ylabel(#5, format(%12.0fc)) ytitle("Avg. Income (RMB)")) ///
	      (connected credit year, msymb(Dh) color(black)) ///
		  (connected avg_inc_trans year, color(black)) ///
		   (connected avg_inc_bus year, msymb(Th) color(black)) ///
		  (connected avg_inc_cap year, color(black)) ///
		  if year<=2007, legend(label(1 "Labor") label(2 "Interest") label(3 "Transfer") label(4 "Business") label(5 "Capital Gains") cols(3)) xtitle("") xlabel(,angle(0))

		  graph export figd8_otherinc.png, replace

	
	**FIGURE B: RENT
	
	gr tw (connected avg_inc_rent year, color(red) lpatter(dash) ytitle("Avg. Income (RMB)") ylabel(#4, format(%12.0fc))) ///
		  (connected sh_rentshouse year, color(blue) lpatter(solid) yaxis(2) ylabel(#3, axis(2)) ytitle("Share of Households", axis(2))) ///
		  if year<=2007, xtitle("") xlabel(,angle(0)) legend(label(1 "Average Rental Income") label(2 "Share of HHs Leasing Property"))
	
		 graph export figd8_rent.png, replace
		 
		 